import 'package:citiesocial/_include.dart';

class MyNotification extends BaseStatefulWidget {
  @override
  State<StatefulWidget> createState() => _MyNotificationState();
}

class _MyNotificationState extends BaseState<MyNotification> {
  final _list = List<SystemMessageEntity>();

  void _loadData() {
    if (Configs.isLogined) {
      LoadingDialog.show(context);
      HttpManager.systemMessage(Configs.userId, Configs.userToken,
              context: context)
          .then((list) {
        LoadingDialog.dismiss(context);
        _list.clear();
        if (list != null && list.length > 0) {
          _list.addAll(list);
        }
        setState(() {});
      });
    }
  }

  @override
  void initState() {
    Future.delayed(Configs.loadDelay, () {
      _loadData();
    });
    super.initState();
  }

  @override
  Widget build(BuildContext context) => Scaffold(
        appBar: AppBarUtils.normal(context, '通知中心'),
        backgroundColor: Colors.white,
        body: SafeArea(
          child: DListView(
            itemCount: _list.length,
            itemBuilder: (_, index) => GestureDetector(
                  child: ItemMenu2(
                    title: _list[index].title,
                    subtitle: _list[index].subtitle,
                  ),
                  onTap: () {
                    final goods = GoodsEntity();
                    goods.goods_id = _list[index].goods_id;
                    goods.goods_name = '';
                    goods.brand_name = '';
                    Navigator.push(
                      context,
                      MaterialPageRoute(
                          builder: (context) => GoodsDetail(goods)),
                    );
                  },
                ),
          ),
        ),
      );
}
